﻿@{
    ViewBag.Title = "管理员编辑";
}
@section Css{

    <link href="/Content/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet"/>
}
<div class="col-sm-6" style="padding-top: 10px;">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form class="form-horizontal m-t" id="form1">
                <div class="form-group">
                    <label class="col-sm-3 control-label">登录名：</label>
                    <div class="col-sm-8">
                        <input id="loginName" name="loginName" minlength="2" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">用户名：</label>
                    <div class="col-sm-8">
                        <input id="userName" type="text" class="form-control" name="userName">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">密码：</label>
                    <div class="col-sm-8">
                        <input id="passWord" type="text" class="form-control" name="passWord">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">用户类型：</label>
                    <div class="col-sm-8">
                        <div class="radio radio-info radio-inline">
                            <input type="radio" id="inlineRadio1" value="2" name="userType" checked="">
                            <label for="inlineRadio1">普通管理员</label>
                        </div>
                        <div class="radio radio-info radio-inline">
                            <input type="radio" id="inlineRadio2" value="1" name="userType">
                            <label for="inlineRadio2">超级管理员</label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3 text-center">
                        <button id="btn_Submit" class="btn btn-primary" type="button">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section Js{
    <script type="text/javascript">
        model = @MvcHtmlString.Create(ViewBag.Json);
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var validator = $("#form1").validate({
            rules: {
                loginName: {
                    required: true
                },
                userName: {
                    required: true
                },
                passWord: {
                    required: true,
                    minlength: 6
                }
            },
            messages: {
                loginName: {
                    required: "请输入登录名"
                },
                userName: {
                    required: "请输入用户名"
                },
                passWord: {
                    required: "请输入密码",
                    minlength: "密码长度不能小于 6 个字母"
                }
            }
        });
        $(function() {
            //dataInit();
            $("#btn_Submit").click(function() {
                if (validator.form()) {
                    var parms = {
                        userId: model.userId,
                        loginName: $.trim($("#loginName").val()),
                        userName: $.trim($("#userName").val()),
                        passWord: $.trim($("#passWord").val()),
                        userType: $("input[name='userType']:checked").val()
                    }
                    $.post("/Account/SysUserSave", parms, function(json) {
                        if (json.result == "success") {
                            layer.msg(json.msg, { icon: 1, time: 2000 }, function(data) {
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(json.msg, { icon: 5 , time: 2000});
                        }
                    }, "json");
                }
            });

        });


        

    </script>
}